<?php
/**
 * Jishupu-Laravel-Vue-Admin
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2021/11/11
 */

namespace App\Http\Resources;

use App\Services\AttachmentService;

/**
 * 信息栏目分类模块资源
 * Class InfoCategoryResource
 * @package App\Http\Resources
 */
class InfoCategoryResource extends BaseResource
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return $this->filterFields([
            'id' => $this->id,
            'type' => $this->type,
            'info_model_id' => $this->info_model_id,
            'parent_id' => $this->parent_id,
            'name' => $this->name,
            'enname' => $this->enname,
            'icon' => $this->icon,
            'cover_image' => AttachmentService::previewList($this->cover_image),
            'keywords' => $this->keywords ? explode(",", $this->keywords) : [],
            'description' => $this->description,
            'href' => $this->href,
            'href_target' => $this->href_target,
            'rel' => $this->rel,
            'sort' => $this->sort,
            'status' => $this->status,
            'index_template' => $this->index_template,
            'list_template' => $this->list_template,
            'article_template' => $this->article_template,
            'created_at' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : "",
            'updated_at' => $this->updated_at ? $this->updated_at->format('Y-m-d H:i:s') : "",
            'info_model' => $this->infoModel
        ]);
    }
}
